<template>
  <!-- 歌单详情页面 -->
  <div>
    <div class="t-icon">
        <i class="iconfont icon-changyongicon-" @click="go_back"></i>
      </div>
    <div class="showBox">
      <div class="top">
        <div class="bgi">
          <img :src="imgUrl" alt />
          <div class="imgbox imgWrap">
            <img :src="imgUrl" alt />
          </div>
        </div>
        <div class="right-box">
          <div class="topwenzi">{{name}}</div>
          <div class="r-box">
            <div class="toux">
              <img :src="imgsrc" alt />
            </div>
            <div class="til">{{tilname}}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="content-box">
      <div class="tags">
        标签:
        <span v-for="(item,index) in tags" :key="index">{{item}}</span>
      </div>
      <div class="cont-box clearFix" @click="toshowtext">
        <pre :class="issomang?'prebox':'unprebox'">简介：{{description}}
        </pre>
        <i class="iconfont" :class="isso?'icon-shousuo':'icon-shousuo1'"></i>
      </div>
      <!-- 歌曲列表 -->
      <div class="text">歌曲列表</div>
      <div>
        <newsong1
          v-for="(item,index) in music"
          :key="item.id"
          :music="item"
          :idx="index"
          @click.native.stop="getlist(item,index)"
        ></newsong1>
      </div>
    </div>
  </div>
</template>
<script>
import { api } from "../../assets/http/api.js";
import newsong1 from "@com/resCom/newsong1.vue";
import { mapMutations } from 'vuex';
export default {
  data() {
    return {
      msg: "",
      imgUrl:
        "http://p1.music.126.net/8xs1V2vPJpb8ywOrlYQFBA==/5868093557713841.jpg",
      name: "",
      isso: false,
      issomang: true,
      music: "",
      imgsrc:"http://p1.music.126.net/8xs1V2vPJpb8ywOrlYQFBA==/5868093557713841.jpg",
      tilname:"默认",
      tags:"默认",
      description:"默认",
      open:true,
      idx:[],
    };
  },
  methods: {
    ...mapMutations(['getUrl',"setTime","setMusic"]),
    toshowtext() {
      this.isso = !this.isso;
      this.issomang = !this.issomang;
    },
     go_back() {
      // this.$store.commit("setMusic", true);
      window.history.go(-1);
    },
    getlist(item,index) {
      this.setMusic(true)
       this.idx.push(index);
      if (this.idx.length == 2) {
        if (this.idx[0] != this.idx[1]) {
          this.open = true;
          this.idx = [];
        } else if (this.idx[0] == this.idx[1]) {
          this.open = false;
          this.idx = [];
        }
      }
      // 如果第一次点击和第二次点击的歌曲不同
      if (this.open) {
          // 字段处理
          let newitem = {};
          this.$axios(api.playmusic + item.id).then(res=>{
          newitem.artist = item.ar[0].name;
          newitem.title = item.name;
          newitem.pic = item.al.picUrl;
          newitem.id = item.id;
          newitem.src = res.data.data[0].url
          this.getUrl(newitem);
          })
      }
       else if (!this.open) {
        // 如果第一次点击和第二次点击的歌曲相同
        this.$store.commit("setMusic", false);
          this.$router.push({
            name: "detail"
          });
      }
    }
  },
  components: {
    newsong1
  },
  async created() {
    let id = this.$route.query.id;
    this.name = this.$route.query.name;
    let res = await this.$axios(api.showlist + `${id}`);
    this.msg = res.data;
    this.music = this.msg.playlist.tracks;
    this.tilname = this.msg.playlist.creator.nickname
    this.imgsrc = this.msg.playlist.avatarUrl
    this.tags = this.msg.playlist.tags;
    this.description = this.msg.playlist.description
  },
  watch: {
    msg() {
      this.imgUrl = this.msg.playlist.coverImgUrl;
    }
  }
};
</script>
<style lang="scss" scope>
.t-icon {
     line-height: 10vh;
    text-align: center;
    width: 20vw;
    position: absolute;
    z-index: 999;
    top: -12px;
    left: -9px;
      i {
       font-size: 35px;
    color: red;
      }
    }
.showBox {
  height: 100%;
  overflow: hidden;
  .top {
    position: relative;
    height: 100%;
    display: flex;
    .bgi {
      height: 44.5vw;
      img {
        filter: blur(25px);
        width: 100%;
        height: 100%;
        box-shadow: 0 0 100px black;
      }
      .imgbox {
        padding: 25px 15px 0;
        position: absolute;
        top: 12px;
        width: 33.5vw;
        img {
          filter: none;
          width: 100%;
          height: 100%;
        }
      }
    }
    .right-box {
      position: absolute;
      left: 36vw;
      top: 12vw;
      color: white;
      .topwenzi {
        margin-bottom: 23px;
        font-size: 20px;
      }
      .r-box {
        display: flex;
        .toux {
          width: 30px;
          border-radius: 50px;
          img {
            width: 100%;
            border-radius: 50px;
          }
        }
        .til {
          line-height: 31px;
          margin-left: 10px;
        }
      }
    }
  }
}
.content-box {
  padding: 10px 10px 10px 15px;
  .cont-box {
    margin-top: 10px;
    .icon-shousuo {
      float: right;
    }
    .icon-shousuo1 {
      float: right;
    }
  }
  .text {
    background-color: #eeeff0;
    margin-left: -15px;
    margin-right: -15px;
    padding-left: 15px;
    margin-bottom: 10px;
    padding-top: 5px;
    padding-bottom: 5px;
  }
  .prebox {
    white-space: pre-wrap; /* css3.0 */
    word-wrap: break-word; /* Internet Explorer 5.5+ */
    line-height: 20px;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    // font-weight: bold;
  }
  .unprebox {
    white-space: pre-wrap; /* css3.0 */
    word-wrap: break-word; /* Internet Explorer 5.5+ */
    line-height: 20px;
    color: #666;
    overflow: none;
    text-overflow: none;
    display: -webkit-box;
    -webkit-line-clamp: none;
    -webkit-box-orient: none;
  }
  .tags {
    span {
      border: 1px solid #eeeeee;
      border-radius: 18px;
      padding: 5px;
      padding-top: 5px;
      width: 65px;
      text-align: center;
      line-height: 13.4px;
      display: inline-block;
      margin-left: 13px;
      font-size: 12px;
      box-shadow: 0 0 1px #eeeeee;
      color: #6d6a6e;
    }
  }
}
</style>